package com.example.controller;

import com.example.pojo.Resign;
import com.example.service.IResignService;
import com.example.vo.ResultVo;
import com.example.vo.per.EmpTurnover;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 离职申请表 前端控制器
 * </p>
 *
 * @author wsl
 * @since 2022-05-05
 */
@RestController
@RequestMapping("/resign")
@Api(tags = "离职申请表",value = "")
@CrossOrigin(allowCredentials = "true")
public class ResignController {

    @Autowired
    private IResignService irs;

    @PostMapping("")
    @ApiOperation("新增离职 申请")
    public ResultVo addRes(@RequestBody Resign resign){
        Integer res = irs.addRes(resign);
        if (res > 0){
            return ResultVo.ok();
        }
        return ResultVo.error();
    }

    @GetMapping("")
    @ApiOperation("查询离职")
    public ResultVo selRes( @RequestParam(defaultValue = "1") Integer pageNum,
                            @RequestParam(defaultValue = "10") Integer pageSize){
        PageInfo<EmpTurnover> info = irs.selResByEmpIdList(pageNum,pageSize);
        if (info != null){
            return ResultVo.response(info);
        }
        return ResultVo.error();
    }


    @PutMapping("")
    @ApiOperation("驳回员工离职")
    public ResultVo uptResIds(@RequestParam("rids") Integer[] rids){
        return irs.uptEmp(rids);
    }

    @DeleteMapping("")
    @ApiOperation("同意员工离职")
    public ResultVo delResIds(@RequestParam("rids") Integer[] rids){
       return irs.delEmp(rids);
    }
}
